/* Copyright (C) 2009, 2011 Christofer Jonsson
 *
 * This file is part of FXH.
 *
 * FXH is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * FXH is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with FXH.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef FXH_SOCKET_H
#define FXH_SOCKET_H

#include "fxh_global.h"
#include <sys/types.h>
#include <stdint.h>

#define FXH_SOCKET_ENCRYPTION ((uint32_t)(1 << 0))

typedef struct
{
   int fd;

   struct
   {
      /* Last transmission */
      struct 
      {
	 /* Bytes sent or received */
	 size_t bytes;

	 /* Transmission duration in milliseconds */
	 double time;
      } last_trans;

   } stats;

} fxh_socket_t;

void fxh_socket_enable(uint32_t options);

void fxh_socket_disable(uint32_t options);

fxh_status_t fxh_socket_listen(fxh_socket_t *listener, 
			       const char *port, 
			       int backlog); 

fxh_status_t fxh_socket_connect(fxh_socket_t *connector, 
				const char *address, 
				const char *port); 

fxh_status_t fxh_socket_accept(fxh_socket_t *listener, 
			       fxh_socket_t *connector);

fxh_status_t fxh_socket_send_all(fxh_socket_t *socket,
				 void *buffer,
				 size_t size);

fxh_status_t fxh_socket_recv_all(fxh_socket_t *socket,
				 void *buffer,
				 size_t size);

fxh_status_t fxh_socket_send(fxh_socket_t *socket,
			     void *buffer,
			     size_t size,
			     size_t *sent);

fxh_status_t fxh_socket_recv(fxh_socket_t *socket,
			     void *buffer,
			     size_t size,
			     size_t *received);

fxh_status_t fxh_socket_close(fxh_socket_t *socket);

#endif /* FXH_SOCKET_H */
